<?php
class UserSettings extends Zend_Form {
	
	private $user;
	private $uploadDir;
	
	public function UserSettings($user, $uploadDir) {
		$this->user = $user;
		$this->uploadDir = $uploadDir;
		$this->__construct();
	}
	
	public function init() {
		$this->setMethod("POST");
		$this->setName("settingForm");
		
		$element = new Zend_Form_Element_Hidden("id");
        $element->setValue($this->user->id);
        $this->addElement($element);
        
        $countryId= City::getCountry($this->user->location)->id;
        $cityId = City::getTopCity($this->user->location)->id;
        $regionId = "";
        if ($this->user->location != $cityId)
       		$regionId = $this->user->location;
        
		/*
        $element = new Zend_Form_Element_Hidden("countryId");
        $element->setValue();
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Hidden("cityId");
        $element->setValue($this->user->id);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Hidden("regionId");
        $element->setValue($this->user->id);
        $this->addElement($element);*/
        
		$element = new Zend_Form_Element_File("photo");
		$element->setLabel("Photo");
		$element->setValue($this->user->big_img);
		$element->addValidator('Count', false, 1);                // ensure only 1 file
        $element->addValidator('Size', false, 1024*1024*10);            // limit to 10 meg
        $element->addValidator('Extension', false, 'JPG,jpg,jpeg,png,gif')
//        ->addValidator('MimeType', false, 
//                   array('image/jpeg',
//                         'image/png',
//                         'image/jpeg'))
        ->addFilter('Rename', implode('_', 
                      array($this->user->id,
                            date('YmdHis'))))
        ->addValidator('NotExists', false, $this->uploadDir)
        ->setDestination($this->uploadDir);
        
		$this->addElement($element);
		
		$element = new Zend_Form_Element_Text("email");
        $element->setLabel("Email");
        $element->setAttrib("disabled","disabled");
        $element->setDescription("Can't be changed.");
        $element->setValue($this->user->email);
        $this->addElement($element);
        
		$element = new Zend_Form_Element_Text("name");
        $element->setLabel("Name");
        $element->setDescription("Better to be the real name to get more trust :D");
        $element->setValue($this->user->name);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Select("country");
        $element->setLabel("Country");
        $element->addMultiOption(0, "-- Select country --");
        $element->addMultiOptions(Country::getAllCountryAsArray());
        $element->setValue($countryId);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Select("city");
        $element->setLabel("City");
        $element->addMultiOption(0, "-- Select city --");
        $element->addMultiOptions(Country::getTopCityByCountryAsArray($countryId));
        $element->setValue($cityId);
        $element->setRegisterInArrayValidator(false);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Select("region");
        $element->setLabel("Region");
        $element->addMultiOptions(array("0"=>"-- Select Region --"));
        $element->addMultiOptions(City::getSubCityAsArray($cityId));
        $element->setValue($regionId);
        $element->setRegisterInArrayValidator(false);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Textarea("introduction");
        $element->setLabel("About You");
        $element->setDescription('Write something about you, e.g - "I live in brommaplan. Love coding such as PHP, JAVA, Python, etc ... Interested in this kind of books, would like to make friends and exchange books to read."');
        $element->setAttrib("rows",4);
        $element->setValue($this->user->introduction);
        $this->addElement($element);
        
        $element = new Zend_Form_Element_Submit("save");
        $this->addElement($element);
	}
}
?>